package movee.utils.network;

import org.apache.hc.client5.http.classic.HttpClient;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;

/**
 *
 *
 * @author movee
 */
public final class RestTemplateUtils {

    private RestTemplateUtils() { }

    public static RestTemplate newRestTemplate(long connectTimeoutMs,
                                               long connectionRequestTimeoutMs,
                                               long responseTimeoutMs,
                                               int maxConnectionSize,
                                               int maxConnectionPerRoute) {

        HttpClient httpClient = ApacheHttpClientUtils.buildHttpClient(connectTimeoutMs, connectionRequestTimeoutMs,
                responseTimeoutMs, maxConnectionSize, maxConnectionPerRoute);
        HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory(httpClient);

        return new RestTemplate(factory);
    }
}
